package com.apartment.own.controller;

import java.util.List;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.apartment.common.annotation.Log;
import com.apartment.common.core.controller.BaseController;
import com.apartment.common.core.domain.AjaxResult;
import com.apartment.common.enums.BusinessType;
import com.apartment.own.domain.OwnResArticleInventory;
import com.apartment.own.service.IOwnResArticleInventoryService;
import com.apartment.common.utils.poi.ExcelUtil;
import com.apartment.common.core.page.TableDataInfo;

/**
 * 物品清单Controller
 * 
 * @author @Dog_E
 * @date 2020-08-28
 */
@RestController
@RequestMapping("/own/inventory")
public class OwnResArticleInventoryController extends BaseController
{
    @Autowired
    private IOwnResArticleInventoryService ownResArticleInventoryService;

    /**
     * 查询物品清单列表
     */
    @PreAuthorize("@ss.hasPermi('own:inventory:list')")
    @GetMapping("/list")
    public TableDataInfo list(OwnResArticleInventory ownResArticleInventory)
    {
        startPage();
        List<OwnResArticleInventory> list = ownResArticleInventoryService.selectOwnResArticleInventoryList(ownResArticleInventory);
        return getDataTable(list);
    }

    /**
     * 导出物品清单列表
     */
    @PreAuthorize("@ss.hasPermi('own:inventory:export')")
    @Log(title = "物品清单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OwnResArticleInventory ownResArticleInventory)
    {
        List<OwnResArticleInventory> list = ownResArticleInventoryService.selectOwnResArticleInventoryList(ownResArticleInventory);
        ExcelUtil<OwnResArticleInventory> util = new ExcelUtil<OwnResArticleInventory>(OwnResArticleInventory.class);
        return util.exportExcel(list, "inventory");
    }

    /**
     * 获取物品清单详细信息
     */
    @PreAuthorize("@ss.hasPermi('own:inventory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ownResArticleInventoryService.selectOwnResArticleInventoryById(id));
    }

    /**
     * 新增物品清单
     */
    @PreAuthorize("@ss.hasPermi('own:inventory:add')")
    @Log(title = "物品清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OwnResArticleInventory ownResArticleInventory)
    {
        return toAjax(ownResArticleInventoryService.insertOwnResArticleInventory(ownResArticleInventory));
    }

    /**
     * 修改物品清单
     */
    @PreAuthorize("@ss.hasPermi('own:inventory:edit')")
    @Log(title = "物品清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OwnResArticleInventory ownResArticleInventory)
    {
        return toAjax(ownResArticleInventoryService.updateOwnResArticleInventory(ownResArticleInventory));
    }

    /**
     * 删除物品清单
     */
    @PreAuthorize("@ss.hasPermi('own:inventory:remove')")
    @Log(title = "物品清单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ownResArticleInventoryService.deleteOwnResArticleInventoryByIds(ids));
    }

    @GetMapping("inventory_list_by_house_id")
    @ApiOperation("根据房源id查询房屋 物业交割信息 -> 房间物品")
    public AjaxResult inventoryListByHouseId(String id){
        return AjaxResult.success(ownResArticleInventoryService.inventoryListByHouseId(id));
    }
}
